/**
 * Copyright (c) 2012-2014 All Rights Reserved.
 */
package com.easy.framwork.jdbc.handlers;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author wy
 * @version v 0.1 2014-1-2 下午8:56:00 wy Exp $
 */
public abstract class AbstractListHandler<T> implements ResultSetHandler<List<T>> {

    protected final Logger log = LoggerFactory.getLogger(getClass());

    /**
     * @see com.easy.framwork.jdbc.handlers.ResultSetHandler#handle(java.sql.ResultSet)
     */
    @Override
    public List<T> handle(ResultSet rs) throws SQLException {
        List<T> rows = new ArrayList<T>();
        int row = 0;
        while (rs.next()) {
            rows.add(this.handleRow(rs, row++));
        }
        return rows;
    }

    /**
     * handle a Row
     * 
     * @param rs
     * @param currentRow
     * @return
     * @throws SQLException
     */
    protected abstract T handleRow(ResultSet rs, int currentRow) throws SQLException;
}
